package com.mhg.collection.theList;

import com.mhg.collection.bean.Student;

import java.util.ArrayList;
import java.util.List;
import java.util.ListIterator;



public class Demo_ListIterator {

	public static void main(String[] args) {
		List list = new ArrayList();
		list.add(new Student("张三", 12));
		list.add(new Student("李四", 22));
		list.add(new Student("王五", 32));
		
		for(int i=0;i<list.size();i++){
			Student stu = (Student)list.get(i);
			System.out.println(stu.getName()+";;;"+stu.getAge());
		}
		ListIterator it = list.listIterator();
		while(it.hasNext()){
			Student stu = (Student)it.next();
			System.out.println(stu.getName());
			if("张三".equals(stu.getName())){
				it.add(new Student("赵六",26));
			}
		}
		//注意 指针 先向后移动 再移动回来 单独写 hasPrevious() 获取不到数据 因为指针是向前移动的 也就是说 从0角标向-1移动
		while(it.hasPrevious()){
			System.out.println("结果:"+it.previous());
		}
	}

}
